package com.feini.ktv.svc.controller.pm;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.feini.ktv.svc.entity.pm.PmResGoods;
import com.feini.ktv.svc.entity.pm.PmResStock;
import com.feini.ktv.svc.service.pm.IPmResGoodsService;
import com.feini.ktv.svc.service.pm.IPmResStockService;
import com.podara.skeleton.controller.SkeletonController;
import com.podara.skeleton.log.annotation.LogLogger;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 库存管理
 * </p>
 *
 * @author jiangzr
 * @since 2021-04-17
 */
@LogLogger
@RestController
public class PmResStockController implements SkeletonController {
    @Autowired
    private IPmResStockService resStockService;
    @Autowired
    private IPmResGoodsService resGoodsService;

    @GetMapping("/queryResStockLikeName/{resSpecName}")
    public List<PmResStock> queryResStockLikeName(@PathVariable("resSpecName") String resSpecName) {
        QueryWrapper<PmResStock> queryStock = new QueryWrapper<PmResStock>();
        queryStock.eq("status", "0");
        if (StringUtils.isNotEmpty(resSpecName) && !"1".equals(resSpecName)) {
            queryStock.like("res_spec_name", resSpecName);
        } else {
            queryStock.between("goods_id", "10000001", "10000020");
        }
        List<PmResStock> stockList = this.resStockService.list(queryStock);
        return stockList;
    }

    @GetMapping("/queryResStockDetail/{goodsId}")
    public List<PmResGoods> queryResStockDetail(@PathVariable("goodsId") String goodsId) {
        QueryWrapper<PmResGoods> querGoods = new QueryWrapper<PmResGoods>();
        querGoods.eq("status", "0");
        querGoods.eq("goods_id", goodsId);
        List<PmResGoods> stockList = this.resGoodsService.list(querGoods);

        return stockList;
    }
}

